//
//  SelcetCityController.swift
//  weather2
//
//  Created by AustinYu on 2020/9/11.
//  Copyright © 2020 mingliang. All rights reserved.
//

import UIKit

//自定义一个协议，想当于制造了一个工具 给干活的人用
protocol SelectCityDelegate {
    func didChangeCity(city:String)
    
}

class SelcetCityController: UIViewController {
    var currentCity = ""
    // 在本页有一些事情发生m，这些事件函数究竟存在哪里 相当于告诉别人这个工具是谁拥有的
    var delegate:SelectCityDelegate?
    
    @IBOutlet weak var cityInput: UITextField!
    @IBOutlet weak var currentCityLabel: UILabel!
    
    @IBAction func dismiss(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
    //3.究竟在哪里使用这些工具
    @IBAction func changeCity(_ sender: Any) {
        delegate?.didChangeCity(city: cityInput.text!)
        dismiss(animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        currentCityLabel.text = currentCity

        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
